package com.onlyphoto.onlymall.mvp.view.binder

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView

import com.onlyphoto.onlymall.R
import com.onlyphoto.onlymall.bean.response.OrderBean

import me.drakeet.multitype.ItemViewBinder

/**
 * Created by gaochujia on 2019-07-01.
 */
class OrderListHeaderBinder : ItemViewBinder<OrderBean, OrderListHeaderBinder.ViewHolder>() {


    override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {
        val root = inflater.inflate(R.layout.item_order_header, parent, false)
        return ViewHolder(root)
    }

    override fun onBindViewHolder(viewHolder: ViewHolder, bean: OrderBean) {
        viewHolder.update(bean)
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

        var orderDate: TextView? = null
        var orderStatus: TextView? = null

        init {
            orderDate = itemView.findViewById(R.id.order_date)
            orderStatus = itemView.findViewById(R.id.order_status)
        }

        @SuppressLint("SetTextI18n")
        fun update(bean: OrderBean) {
            orderDate?.text = "订单日期：${bean.date_ymd}"
            orderStatus?.setTextColor(ContextCompat.getColor(itemView.context, R.color.text_color))

            if (bean.state == 1 && bean.state_extra == 0) {
                orderStatus?.text = "等待付款"
                orderStatus?.setTextColor(ContextCompat.getColor(itemView.context, R.color.red))
            }

            when (bean.state) {
                2 ->
                    orderStatus?.text = "待发货"
                3 ->
                    orderStatus?.text = "待收货"
                5 ->
                    orderStatus?.text = "已完成"
            }

            when (bean.state_extra) {
                10 ->
                    orderStatus?.text = "申请退货中"
                11 ->
                    orderStatus?.text = "退货被驳回"
                12 ->
                    orderStatus?.text = "同意退货"
                13 ->
                    orderStatus?.text = "退货成功"
                14 ->
                    orderStatus?.text = "交易关闭"
                15 ->
                    orderStatus?.text = "交易关闭"
            }
        }
    }
}
